const path = require('path')
const fs = require('fs')

// 根据日期存放目录,不存在则创建,然后返回目录
const getFolderPath = (folderName) => {

    const date = new Date()
    const toPad2 = num => num.padStart(2, '0')
    const folderDate = `${date.getFullYear()}${toPad2(`${date.getMonth() + 1}`)}${toPad2(`${date.getDate()}`)}`
    const folderPath = path.resolve(`${process.cwd()}/static/${folderName}/${folderDate}`)
    const staticPath = `/${folderName}/${folderDate}`

    if (!fs.existsSync(folderPath)) {
      fs.mkdirSync(folderPath)
    }

    return {
      folderPath,
      staticPath
    }
}

module.exports = {
    getFolderPath
}
